package com.chaodev.base.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.chaodev.base.dao.InteractionGameDao;
import com.chaodev.base.dto.InteractionGameDto;
import com.chaodev.base.model.InteractionGame;
import com.chaodev.base.service.InteractionGameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InteractionGameServiceImpl implements InteractionGameService {
    
    @Autowired
    private InteractionGameDao interactionGameDao;

    @Override
    public boolean addInteractionGame(InteractionGame interactionGame) {
        return interactionGameDao.insertInteractionGame(interactionGame) != 0;
    }

    @Override
    public boolean editInteractionGame(InteractionGame interactionGame) {
        return interactionGameDao.updateInteractionGame(interactionGame) != 0;
    }

    @Override
    public boolean saveInteractionGame(InteractionGame interactionGame) {
        if (ObjectUtil.isNotNull(interactionGame.getId()) && !"".equals(interactionGame.getId())){
            interactionGame.setUpdateUser(interactionGame.getCreateUser());
            return editInteractionGame(interactionGame);
        }
        return addInteractionGame(interactionGame);
    }

    @Override
    public boolean removeInteractionGame(InteractionGame interactionGame) {
        return interactionGameDao.deleteInteractionGame(interactionGame.getId()) != 0;
    }

    @Override
    public List<InteractionGame> getInteractionGameList(InteractionGameDto interactionGameDto) {
        return interactionGameDao.selectInteractionGameList(interactionGameDto);
    }

    @Override
    public InteractionGame getInteractionGameById(InteractionGame interactionGame) {
        return interactionGameDao.selectInteractionGameById(interactionGame.getId());
    }

    @Override
    public PageInfo<InteractionGame> getInteractionGamePage(InteractionGameDto interactionGameDto) {
        PageHelper.startPage(interactionGameDto.getPage(),interactionGameDto.getRows());
        List<InteractionGame> list = interactionGameDao.selectInteractionGameList(interactionGameDto);
        PageInfo<InteractionGame> pageInfo = new PageInfo<>(list, interactionGameDto.getRows());
        return pageInfo;
    }
}
